package com.sky.mapper.admin;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 分页查询
     */
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 新增菜品
    */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into dish (name,category_id,price,image,description,`status`,create_time,update_time,create_user,update_user,make_time)\n" +
            "values(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{makeTime})")
    void insert(Dish dish);

    /**
     * 根据id查询菜品
     */
    @Select("select d.*,c.name as categoryName from dish as d left join category as c on d.category_id = c.id where d.id = #{id}")
    DishVO queryById(Long id);

    /**
     * 删除，批量删除
     */
    void deleteByIds(List<Long> ids);

    /**
     * 查询起售状态的菜品
     */
    List<Dish> queryOnSaleDish(List<Long> ids);

    /**
     * 根据分类id查询菜品
     */
    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<DishVO> queryByCategoryId(Long categoryId);

    /**
     * 修改菜品
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 查询未起售菜品
     */
    List<Dish> queryDishStatus(List<Long> dishIdList);
}
